package com.defysoft.waukids.message;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.defysoft.waukids.BaseFragment;
import com.defysoft.waukids.R;
import com.defysoft.waukids.slide.Main_Slide_Option;

public class MessageMainWriteTwoF extends BaseFragment implements OnClickListener{
	View view;
	//툴바용
	//메인용
	EditText editText[] = new EditText[7];
	TextView textView[] = new TextView[2];
	/*java.util.Calendar cal = java.util.Calendar.getInstance(); */
	String nowDate;
	long now = System.currentTimeMillis();
	Date date = new Date(now);
	SimpleDateFormat CurFormat = new SimpleDateFormat("yyyy - MM - dd");
	
	String memberPhone;
	
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.message_main_write_two_f, null);
		setStartData();
		return view;
	}

@Override
public void setStartData() {
	super.setStartData();
	memberPhone = ((MessageMainWrite)getActivity()).memberPhone;
	
	editText[0] = (EditText)view.findViewById(R.id.MESSAGE_TWO_TYPEONE_CONTENTS);
	editText[1] = (EditText)view.findViewById(R.id.MESSAGE_TWO_TYPETWO_CONTENTS);
	editText[2] = (EditText)view.findViewById(R.id.MESSAGE_TWO_TYPETHREE_CONTENTS);
	editText[3] = (EditText)view.findViewById(R.id.MESSAGE_TWO_TYPEFOUR_CONTENTS);
	editText[4] = (EditText)view.findViewById(R.id.MESSAGE_TWO_TYPEFIVE_CONTENTS);
	editText[5] = (EditText)view.findViewById(R.id.MESSAGE_TWO_TYPESIX_CONTENTS);
	editText[6] = (EditText)view.findViewById(R.id.MESSAGE_TWO_TYPEFSEV_CONTENTS);
	editText[2].setOnClickListener(this);
	/*for (int i = 0; i < editText.length; i++) {
		editText[i].setOnClickListener(this);
	}*/
	textView[0] = (TextView)view.findViewById(R.id.MESSAGE_TWO_DATE);
	textView[1] = (TextView)view.findViewById(R.id.MESSAGE_TWO_PARENTS);
	//기본값 입력.
	nowDate =  CurFormat.format(date);
	editText[0].setText(((MessageMainWrite)getActivity()).student.Name);
	if (memberPhone.equals("") || memberPhone.equals(null)) {
		editText[3].setHint("보호자 연락처를 입력하세요.");
	} else {
		editText[3].setText(memberPhone);
	}
	textView[0].setText(nowDate);
	textView[1].setText(((MessageMainWrite)getActivity()).student.Name+" 어린이 보호자 "+((MessageMainWrite)getActivity()).member.Name);
	
}

@Override
public void onClick(View v) {
	DialogFragment newFragment = new TimePickerFragment();
	switch (v.getId()) {
	case R.id.MESSAGE_TWO_TYPETHREE_CONTENTS:
		newFragment.show(getChildFragmentManager(), "timePicker");		
		break;
	}
}

public class TimePickerFragment extends DialogFragment implements
		TimePickerDialog.OnTimeSetListener {

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final Calendar c = Calendar.getInstance();
		int hour = c.get(Calendar.HOUR_OF_DAY);
		int minute = c.get(Calendar.MINUTE);

		// Create a new instance of TimePickerDialog and return it
		return new TimePickerDialog(getActivity(), this, hour, minute, true);
	}

	public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
				editText[2].setText(hourOfDay + " 시 " + minute + " 분");
	}

}

}
